home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Games / NeXTmj / Source / TileDescription.cc < prev    next >
Text File  |  1991-03-23  |  7KB  |  338 lines

  1.  
  2. /*
  3.  $Author$
  4.  $Header$
  5.  *
  6.  $Log$
  7.  */
  8.  
  9. #import    "TileDescription.h"
  10. #import    "Tile.h"
  11.  
  12. extern "C" {
  13. #import    <assert.h>
  14.  
  15. #import    "mj.h"
  16. }
  17.  
  18. extern "Objective-C" {
  19. #import    <objc/objc.h>
  20. }
  21.  
  22.  
  23. TileDescription::TileDescription( int loc ) {
  24.  
  25.     int    my_loc_z;
  26.     
  27.     
  28.                                                 // Set up default cases.
  29.     left_list    += ( loc -1 );
  30.     right_list     += ( loc + 1 );
  31.     
  32.                                                 // Set up the left and right
  33.                                                 //    associations for the tile's location.
  34.     switch( loc ) {
  35.         case 0:
  36.         case 12:
  37.         case 20:
  38.         case 57:
  39.         case 67:
  40.         case 75:
  41.         case 87:
  42.         case 93:
  43.         case 99:
  44.         case 105:
  45.         case 111:
  46.         case 117:
  47.         case 123:
  48.         case 127:
  49.         case 131:
  50.         case 135:
  51.         case 139:
  52.         case 141:
  53.             left_list.empty();
  54.             break;
  55.         case 11:
  56.         case 19:
  57.         case 29:
  58.         case 56:
  59.         case 66:
  60.         case 74:
  61.         case 86:
  62.         case 92:
  63.         case 98:
  64.         case 104:
  65.         case 110:
  66.         case 116:
  67.         case 122:
  68.         case 126:
  69.         case 130:
  70.         case 134:
  71.         case 138:
  72.         case 140:
  73.         case 142:
  74.             right_list.empty();
  75.             break;
  76.         case 30:
  77.             left_list.empty();
  78.             right_list += 43;
  79.             break;
  80.         case 42:
  81.             right_list.empty();
  82.             right_list += 55;
  83.             break;
  84.         case 43:
  85.             left_list.empty();
  86.             left_list += 30;
  87.             break;
  88.         case 55:
  89.             left_list += 42;
  90.             break;
  91.         case 143:
  92.             left_list.empty();
  93.             right_list.empty();
  94.             break;
  95.         default:
  96.             assert( loc );
  97.     }
  98.     
  99.                                                 // Set up the covered associations
  100.                                                 //    for the tile's location.
  101.     switch( loc ) {
  102.         case 13:    case 14:    case 15:    case 16:
  103.         case 17:    case 18:
  104.             covered_by_list += ( 87 + loc - 13 );
  105.             break;
  106.         case 22:    case 23:    case 24:    case 25:    
  107.         case 26:    case 27:
  108.             covered_by_list += ( 93 + loc - 22 );
  109.             break;
  110.         case 34:    case 35:    case 36:    case 37:
  111.         case 38:    case 39:
  112.             covered_by_list += ( 99 + loc - 34 );
  113.             break;
  114.         case 46:    case 47:    case 48:    case 49:
  115.         case 50:    case 51:
  116.             covered_by_list += ( 105 + loc - 46 );
  117.             break;
  118.         case 59:    case 60:    case 61:    case 62:
  119.         case 63:    case 64:
  120.             covered_by_list += ( 111 + loc - 59 );
  121.             break;
  122.         case 68:    case 69:    case 70:    case 71:
  123.         case 72:    case 73:
  124.             covered_by_list += ( 117 + loc - 68 );
  125.             break;
  126.         case 94:    case 95:    case 96:    case 97:
  127.             covered_by_list += ( 123 + loc - 94 );
  128.             break;
  129.         case 100:    case 101:    case 102:    case 103:
  130.             covered_by_list += ( 127 + loc - 100 );
  131.             break;
  132.         case 106:    case 107:    case 108:    case 109:
  133.             covered_by_list += ( 131 + loc - 106 );
  134.             break;
  135.         case 112:    case 113:    case 114:    case 115:
  136.             covered_by_list += ( 135 + loc - 112 );
  137.             break;
  138.         case 128:    case 129:
  139.             covered_by_list += ( 139 + loc - 128 );
  140.             break;
  141.         case 132:    case 133:
  142.             covered_by_list += ( 141 + loc - 132 );
  143.             break;
  144.         case 139:    case 140:
  145.         case 141:    case 142:
  146.             covered_by_list += 143;
  147.             break;
  148.     }
  149.  
  150.                                                 // Calculate the tile's location
  151.                                                 //    on the Game Board.
  152.                                                 // We're going to stuff row and column
  153.                                                 //    values in x,y.  They're adjusted
  154.                                                 //    below.
  155.     switch( loc ) {
  156.         case 0:        case 1:        case 2:        case 3:
  157.         case 4:        case 5:        case 6:        case 7:
  158.         case 8:        case 9:        case 10:    case 11:
  159.             my_loc.x = 1 + loc;
  160.             my_loc.y = 7;
  161.             my_loc_z = 0;
  162.             break;
  163.         case 12:    case 13:    case 14:    case 15:
  164.         case 16:    case 17:    case 18:    case 19:
  165.             my_loc.x = 3 + loc - 12;
  166.             my_loc.y = 6;
  167.             my_loc_z = 0;
  168.             break;
  169.         case 20:    case 21:    case 22:    case 23:
  170.         case 24:    case 25:    case 26:    case 27:
  171.         case 28:    case 29:
  172.             my_loc.x = 2 + loc - 20;
  173.             my_loc.y = 5;
  174.             my_loc_z = 0;
  175.             break;
  176.         case 30:
  177.             my_loc.x = 0;
  178.             my_loc.y = 3.5;
  179.             my_loc_z = 0;
  180.             break;
  181.         case 31:    case 32:    case 33:    case 34:
  182.         case 35:    case 36:    case 37:    case 38:
  183.         case 39:    case 40:    case 41:    case 42:
  184.             my_loc.x = 1 + loc - 31;
  185.             my_loc.y = 4;
  186.             my_loc_z = 0;
  187.             break;
  188.         case 43:    case 44:    case 45:    case 46:
  189.         case 47:    case 48:    case 49:    case 50:
  190.         case 51:    case 52:    case 53:    case 54:
  191.             my_loc.x = 1 + loc - 43;
  192.             my_loc.y = 3;
  193.             my_loc_z = 0;
  194.             break;
  195.         case 55:    case 56:
  196.             my_loc.x = 13 + loc - 55;
  197.             my_loc.y = 3.5;
  198.             my_loc_z = 0;
  199.             break;
  200.         case 57:    case 58:    case 59:    case 60:
  201.         case 61:    case 62:    case 63:    case 64:
  202.         case 65:    case 66:
  203.             my_loc.x = 2 + loc - 57;
  204.             my_loc.y = 2;
  205.             my_loc_z = 0;
  206.             break;
  207.         case 67:    case 68:    case 69:    case 70:
  208.         case 71:    case 72:    case 73:    case 74:
  209.             my_loc.x = 3 + loc - 67;
  210.             my_loc.y = 1;
  211.             my_loc_z = 0;
  212.             break;
  213.         case 75:    case 76:    case 77:    case 78:
  214.         case 79:    case 80:    case 81:    case 82:
  215.         case 83:    case 84:    case 85:    case 86:
  216.             my_loc.x = 1 + loc - 75;
  217.             my_loc.y = 0;
  218.             my_loc_z = 0;
  219.             break;
  220.  
  221.         case 87:    case 88:    case 89:    case 90:
  222.         case 91:    case 92:    
  223.             my_loc.x = 4 + loc - 87;
  224.             my_loc.y = 6;
  225.             my_loc_z = 1;
  226.             break;
  227.         case 93:    case 94:    case 95:    case 96:    
  228.         case 97:    case 98:
  229.             my_loc.x = 4 + loc - 93;
  230.             my_loc.y = 5;
  231.             my_loc_z = 1;
  232.             break;
  233.         case 99:    case 100:    case 101:    case 102:
  234.         case 103:    case 104:    
  235.             my_loc.x = 4 + loc - 99;
  236.             my_loc.y = 4;
  237.             my_loc_z = 1;
  238.             break;
  239.         case 105:    case 106:    case 107:    case 108:    
  240.         case 109:    case 110:
  241.             my_loc.x = 4 + loc - 105;
  242.             my_loc.y = 3;
  243.             my_loc_z = 1;
  244.             break;
  245.         case 111:    case 112:    case 113:    case 114:
  246.         case 115:    case 116:    
  247.             my_loc.x = 4 + loc - 111;
  248.             my_loc.y = 2;
  249.             my_loc_z = 1;
  250.             break;
  251.         case 117:    case 118:    case 119:    case 120:    
  252.         case 121:    case 122:
  253.             my_loc.x = 4 + loc - 117;
  254.             my_loc.y = 1;
  255.             my_loc_z = 1;
  256.             break;
  257.  
  258.         case 123:    case 124:    case 125:    case 126:
  259.             my_loc.x = 5 + loc - 123;
  260.             my_loc.y = 5;
  261.             my_loc_z = 2;
  262.             break;
  263.         case 127:    case 128:    case 129:    case 130:
  264.             my_loc.x = 5 + loc - 127;
  265.             my_loc.y = 4;
  266.             my_loc_z = 2;
  267.             break;
  268.         case 131:    case 132:    case 133:    case 134:
  269.             my_loc.x = 5 + loc - 131;
  270.             my_loc.y = 3;
  271.             my_loc_z = 2;
  272.             break;
  273.         case 135:    case 136:    case 137:    case 138:
  274.             my_loc.x = 5 + loc - 135;
  275.             my_loc.y = 2;
  276.             my_loc_z = 2;
  277.             break;
  278.  
  279.         case 139:    case 140:    
  280.             my_loc.x = 6 + loc - 139;
  281.             my_loc.y = 4;
  282.             my_loc_z = 3;
  283.             break;
  284.         case 141:    case 142:
  285.             my_loc.x = 6 + loc - 141;
  286.             my_loc.y = 3;
  287.             my_loc_z = 3;
  288.             break;
  289.             
  290.         case 143:
  291.             my_loc.x = 6.5;
  292.             my_loc.y = 3.5;
  293.             my_loc_z = 4;
  294.             break;
  295.         default:
  296.             assert( loc );
  297.     }
  298.     
  299.                                                 // Adjust the x/y location by
  300.                                                 //    Game Piece size.
  301.                                                 // The x location is given an additional
  302.                                                 //    shift to the left for more of a 3d
  303.                                                 //    effect.
  304.     my_loc.x *= TILE_SIZE - TILE_SHIFT;
  305.     my_loc.x -= my_loc_z * TILE_SHIFT;
  306.     my_loc.y *= TILE_SIZE - TILE_SHIFT;
  307.     my_loc.y += my_loc_z * TILE_SHIFT;
  308. }
  309.  
  310.  
  311. IntegerList& TileDescription::leftList( void ) {
  312.     
  313.     
  314.     return left_list;
  315. }
  316.  
  317.  
  318. IntegerList& TileDescription::rightList( void ) {
  319.         
  320.         
  321.     return right_list;
  322. }
  323.  
  324.  
  325. IntegerList& TileDescription::coveredList( void ) {
  326.     
  327.     
  328.     return covered_by_list;
  329. }
  330.  
  331.  
  332. NXPoint TileDescription::tileLocation( void ) {
  333.         
  334.         
  335.     return my_loc;
  336. }
  337.  
  338.